<template>
  <div>
    <div class="clearfix">
      <el-menu
        :default-active="activeIndex"
        class="el-menu-demo"
        mode="horizontal"
        @select="handleSelect"
        background-color="#2a2d2f"
        text-color="#fff"
        active-text-color="#ffd04b"
        style="border-bottom: none;display: inline-block;float: left">
        <el-menu-item index="1">活动任务</el-menu-item>
        <el-menu-item index="2">完成任务</el-menu-item>
      </el-menu>
      <el-button type="primary" style="float: right;border-radius: 0 4px 4px 0;margin-top: 10px;margin-right: 15px;" @click="SearchMission">搜索任务</el-button>
      <el-input
        placeholder="搜索任务编号"
        v-model="Search"
        prefix-icon="el-icon-search"
        clearable
        class="searchMission">
      </el-input>
    </div>
    <div style="padding:15px;">
      <div style="background-color: white;">
        <div style="margin: 0 15px;">
          <div style="height: 750px; overflow: auto">
            <div class="card card-1" v-for="item in Missions" @click="openMission(item.id)">
              <el-tag :type="item.missionTag" class="cardTag">{{item.status}}</el-tag>
              <p>{{item.missionName}}</p>
              <p>{{item.type}}</p>
              <p style="color: red">{{item.overDate}}</p>
              <div class="block">
              </div>
            </div>
            <div style="margin-top: 10px;text-align: center">
              <el-pagination
                background
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[5, 6, 7, 8]"
                :page-size="PageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
              </el-pagination>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  const axios = require('axios');
  export default {
    name: "directed",
    data() {
      return {
        activeIndex : '1',

        //分页数据
        currentPage: 1,
        total: 0,
        PageSize: 5,
        currentTable: 1,

        Search: '',

        Missions:[],
      }
    },
    created() {
      axios.post("/getMyCreateMissionA",{"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id")}).then(res => {
        this.Missions = res.data.list;
        this.total = res.data.total;
      })
    },
    methods: {
      handleSelect(key) {
        if(key == 1){
          axios.post('/getMyCreateMissionA', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id")}).then(res => {
            this.Missions = res.data.list;
            this.total = res.data.total;
            this.currentPage = 1;
            this.currentTable = 1;
          })
        }else{
          axios.post('/getMyCreateMissionC', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id")}).then(res => {
            this.Missions = res.data.list;
            this.total = res.data.total;
            this.currentPage = 1;
            this.currentTable = 2;
          })
        }
      },
      handleSizeChange(val) {
        this.PageSize = val;
        if(this.currentTable = 1){
          axios.post('/getMyCreateMissionA', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id")}).then(res => {
            this.Missions = res.data.list;
            this.total = res.data.total;
            this.currentPage = 1;
            this.currentTable = 1;
          })
        }else if(this.currentTable = 2){
          axios.post('/getMyCreateMissionC', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id")}).then(res => {
            this.Missions = res.data.list;
            this.total = res.data.total;
            this.currentPage = 1;
            this.currentTable = 2;
          })
        }else{
          axios.post('/getMyCreateMissionS', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id"),"content":this.Search}).then(res => {
            this.Missions = res.data.list;
            this.total = res.data.total;
            this.currentPage = 1;
            this.currentTable = 3;
          })
        }
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        if(this.currentTable = 1){
          axios.post('/getMyCreateMissionA', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id")}).then(res => {
            this.Missions = res.data.list;
            this.total = res.data.total;
            this.currentTable = 1;
          })
        }else if(this.currentTable = 2){
          axios.post('/getMyCreateMissionC', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id")}).then(res => {
            this.Missions = res.data.list;
            this.total = res.data.total;
            this.currentTable = 2;
          })
        }else{
          axios.post('/getMyCreateMissionS', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id"),"content":this.Search}).then(res => {
            this.Missions = res.data.list;
            this.total = res.data.total;
            this.currentTable = 3;
          })
        }
      },
      SearchMission(){
        let reg = /^\d+$|^\d+[.]?\d+$/;
        if(this.Search == ""){
          this.$message.error("搜索不能为空")
        }else if(!reg.test(this.Search)) {
          this.$message.error("只能输入数字编号搜索")
        }else{
          axios.post('/getMyCreateMissionS', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id"),"content":this.Search}).then(res => {
            this.Missions = res.data.list;
            this.total = res.data.total;
            this.currentPage = 1;
            this.currentTable = 3;
          })
        }
      },
      openMission(id) {
        this.$emit('openMission',id);
      }
    }

  }
</script>

<style>

</style>
